<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Name extends ADMIN_Controller  {
	
	function __construct(){
		parent::__construct();
		$this->load->model("showlist");
		$this->load->model("profile_model");
		$this->load->helper("url");
		$this->load->helper('form');
		$this->load->library("pagination");
		$this->load->library("session");
	}
	
	public function export() {
		$search = $this->security->xss_clean($this->input->get('search'));
		$batch = $this->security->xss_clean($this->input->get('batch'));
		$dept = $this->security->xss_clean($this->input->get('dept'));
		$this->load->library('excel');
		$sheet = new PHPExcel();
		$sheet->getProperties()->setTitle('Alumni List')->setDescription('Alumni List');
		$sheet->setActiveSheetIndex(0);
		$total_rows = $this->showlist->record_count($batch, $dept, $search);
		$alumni_data = $this->showlist->fetch_alumni($total_rows, 0, $batch, $dept, $search);
		$col = 0;
		foreach ($alumni_data[0] as $field=>$value) {
			$sheet->getActiveSheet()->setCellValueByColumnAndRow($col, 1, $field);
			$col++;
		}
		$row = 2;
		foreach ($alumni_data as $data) {
		$col = 0;
			foreach ($data as $field_val) {
				$sheet->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $field_val);
				$col++;
			}
		$row++;
		}
		$sheet_writer = PHPExcel_IOFactory::createWriter($sheet, 'Excel5');
		header('Content-Type: application/vnd.ms-excel');
		header('Content-Disposition: attachment;filename="alumni_'.date('dMy').'.xls"');
		header('Cache-Control: max-age=0');

		$sheet_writer->save('php://output');
	}
	
	
	public function index() {
		redirect('admin/name/show');
	}
	
	public $dept = array(
			0 =>"Dept",
			1 => "BT",
			6 => "ISE"
	);
	
	public $batch = array (
			0 => "Batch",
			2004 => "2004",
			2005 => "2005",
			2006 => "2006",
			2007 => "2007",
			2008 => "2008",
			2009 => "2009",
			2010 => "2010",
			2011 => "2011",
			2012 => "2012",
			2013 => "2013"			
			);
	 
	public function show() {
		$search = $this->security->xss_clean($this->input->get('search'));
		$batch = $this->security->xss_clean($this->input->get('batch'));
		$dept = $this->security->xss_clean($this->input->get('dept'));
		$page = $this->security->xss_clean($this->input->get('per_page'));
		$config = array();
        $config["base_url"] = base_url() . "index.php/admin/name/show?batch=".$batch."&dept=".$dept."&search=".$search;
        $config["total_rows"] = $this->showlist->record_count($batch, $dept, $search);
		$config["per_page"] = 15;
        $config["uri_segment"] = 5;
        $config['page_query_string'] = TRUE;
        $config['full_tag_open'] = '</opening tag><ul class="pagination">';
        $config['full_tag_close'] = '</ul><opening tag>';
        $config['first_link'] = 'First';
        $config['first_tag_open'] = '<li>';
        $config['first_tag_close'] = '</li><opening tag>';
        $config['last_link'] = 'Last';
        $config['last_tag_open'] = '</opening tag><li>';
        $config['last_tag_close'] = '</li><opening tag>';
        $config['num_tag_open'] = '</opening tag><li>';
        $config['num_tag_close'] = '</li><opening tag>';
        $config['cur_tag_open'] = '</opening tag><li class="active"><a href="#">';
        $config['cur_tag_close'] = '<span class="sr-only">(current)</span></a></li><opening tag>';
        $config['next_link'] = 'Next';
        $config['prev_link'] = 'Previous';
        $config['next_tag_open'] = '</opening tag><li>';
        $config['next_tag_close'] = '</li><opening tag>';
        $config['prev_tag_open'] = '</opening tag><li>';
        $config['prev_tag_close'] = '</li><opening tag>';
        
        $this->pagination->initialize($config);
        $this->data["results"] = $this->showlist->fetch_alumni($config["per_page"], $page, $batch, $dept, $search);
        if($config["total_rows"] > 15)
				$this->data["links"] = $this->pagination->create_links();
        $this->render_page('admin_show_few');
    }
    
    public function view($id = '') {
    	$this->data['query'] = $this->profile_model->show_profile($id);
    	$this->render_page('admin_profile_view');
    }
    
    public function edit($id = '') {
    	$this->data['query'] = $this->profile_model->show_profile($id);
    	$this->render_page('admin_profile_edit_view');
    }
    
    public function process() {
    	$id = $this->profile_model->edit_profile();
		if($id)
    		redirect("admin/name/view/".$id);
		else
			redirect("admin/name/show");
    }
	
}

/* End of file index.php */
/* Location: ./application/controllers/welcome.php */